﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using log4net;

namespace Foothill.Common.Logging
{
    internal class Log4NetLogger : ILogger
    {
        private ILog _logger;

        public Log4NetLogger()
        {
            _logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        }
        
        public void Log(FoothillModule module, LogLevel level, string message)
        {
            string logEntry = string.Format("[{0}] {1}", module.ToString("G"), message);

            switch (level)
            {
                case LogLevel.Info:
                    _logger.Info(logEntry);
                    break;
                case LogLevel.Warn:
                    _logger.Warn(logEntry);
                    break;
                case LogLevel.Debug:
                    _logger.Debug(logEntry);
                    break;
            }
        }

        public void Error(FoothillModule module, string message, Exception exception)
        {
            string logEntry = string.Format("[{0}] {1}", module.ToString("G"), message);
            _logger.Error(logEntry, exception);
        }

        public void Error(FoothillModule module, string message)
        {
            string logEntry = string.Format("[{0}] {1}", module.ToString("G"), message);
            _logger.Error(logEntry);
        }
    }
}
